<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #div1{
            width: 100px;
            height: 100px;
            background: yellow;
        }
    </style>
</head>
<body>
    <div id='div1'></div>
    <script>
        //自执行表达式会直接执行,不会等定时器的时间,所以需要用闭包将函数返回,作为定时器的函数
        setTimeout((function(color){
            return function(){
                document.getElementById('div1').style.background=color
            }
        })('green'),2000)
    </script>
</body>
</html>